package.path = package.path .. ";./app/common/lib/?.lua;"

-- base config
local svr_ip = "192.168.6.211"
local svr_port = 8181
local relpay_logpath = "http://192.168.6.211/"

local check = function ()
    print("---------- check config start ----------")
    local dbstruct = require("dbstruct")
    if dbstruct.rs_money.fields.diamond ~= 0 then
        return "error: dbstruct.rs_money.fields.diamond ~= 0 !!!"
    end
    if dbstruct.rs_money.fields.basemoney ~= 0 then
        return "error: dbstruct.rs_money.fields.basemoney ~= 0 !!!"
    end
    if dbstruct.rs_money.fields.lock_diamond ~= 0 then
        return "error: dbstruct.rs_money.fields.lock_diamond ~= 0 !!!"
    end

    local filename = "./app/config/config_svrs"
    local f = io.open(filename)
    if not f then
        return "error: run_check load_config open " .. filename .." failed"
    end

    local source = f:read "*a"
    f:close()

    local tmp = {}
    local ftmp, err = load(source, "@" .. filename, "bt", tmp)
    if ftmp == nil then
        return "error: run_check load_config load " .. filename .." failed", err
    end
    local success, err = pcall(ftmp)
    if not success then
        return "error: run_check load_config call " .. filename .." failed", err
    end

    if tmp.gatenode.link_ip ~= svr_ip then
        return "error: gate ip error !!!"
    end
    if tmp.gatenode.link_port ~= svr_port then
        return "error: gate port error !!!"
    end
    if tmp.gatenode.relpay_logpath ~= relpay_logpath then
        return "error: gate relpay_logpath error !!!"
    end
    print("---------- check config over  ----------")
    return true
end

local result, msg, err = check()
if result ~= true then
    print("###############################")
    print("########### ERROR #############")
    print(result, msg, err)
    print("########### ERROR #############")
    print("###############################")
    os.execute("sleep 3")
    return false
end
return true
